package com.example.demo.service.system;

import com.example.demo.dao.system.RoleDAO;
import com.example.demo.model.system.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleService {
    @Autowired
    private RoleDAO dao;


    public Role selectByRoleId(Integer role_id) {
        return dao.selectByRoleId(role_id);
    }

    public List<Role> selectAll() {
        return dao.selectAll();
    }

    public List<Role> findRole(String role_name, String desc) {
        return dao.findRole(role_name, desc);
    }

    public Integer addRole(Role role) {
        return dao.addRole(role);
    }

    public Integer deleteById(Integer role_id) {
        return dao.deleteById(role_id);
    }

    public Integer updateById(Role role) {
        return dao.updateById(role);
    }

    public Boolean save(Role role) {
        Boolean flag = false;

        if (role.getRole_id() != null) {
            flag = dao.updateById(role) == 1;
        } else {
            flag = dao.addRole(role) == 1;
        }

        return flag;
    }
}
